<template>
	<view class="main" :key="refreshKey">
		<uv-modal ref="rateModal" title="提示" confirmText="我知道了">
			<view class="slot-content">
				<view class="holding-project-item">
					<view class="holding-project-item-label">
						项目收益率：
					</view>
					<view class="holding-project-item-content">
						{{selectedProject.rate}}%
					</view>
				</view>
				<view class="holding-project-item">
					<view class="holding-project-item-label">
						等级加息：
					</view>
					<view class="holding-project-item-content">
						{{selectedProject.levelAdditionalRate}}%
					</view>
				</view>
				<view class="holding-project-item">
					<view class="holding-project-item-label">
						加息券：
					</view>
					<view class="holding-project-item-content">
						{{selectedProject.couponAdditionalRate}}%
					</view>
				</view>
			</view>
		</uv-modal>
		<uv-modal ref="amountModal" title="提示" confirmText="我知道了">
			<view class="slot-content">
				<view class="holding-project-item">
					<view class="holding-project-item-label">
						购买金额：
					</view>
					<view class="holding-project-item-content">
						{{selectedProject.buyInAmount}}
					</view>
				</view>
				<view class="holding-project-item">
					<view class="holding-project-item-label">
						现金券抵扣：
					</view>
					<view class="holding-project-item-content">
						{{selectedProject.cashCouponValue}}
					</view>
				</view>
			</view>
		</uv-modal>
		<view style="padding-bottom: 32rpx;">
			<view class="item animate__bounceIn" v-for="(project,index) in projects" :key="index" style="animation-duration: 2s;">
				<view class="item-title">
					<text>[{{ project.projectName }}]</text>
					<text class="check-btn" @click="projectContractPage(project.buyInRecordId)">查看详情</text>
				</view>
				<view style="margin-top: 32rpx;" class="item-content">
					<view class="item-content-w">
						<view class="item-content-box">
							<text class="txt1">{{ project.term }}</text>
							<text class="txt2">投资期限</text>
							<text class="txt3">（天）</text>
						</view>
						<view class="item-content-box">
							<text class="txt1">{{ project.totalRate + '%' }}</text>
							<text class="txt2">是</text>
							<text class="txt3">（%）</text>
						</view>
						<view class="item-content-box">
							<text class="txt1">{{ project.singleTimeIncome }}</text>
							<text class="txt2">每期收益</text>
							<text class="txt3">（天）</text>
						</view>
						<view class="item-content-box">
							<text class="txt1">{{project.buyInAmount}}</text>
							<text class="txt2">起购金额</text>
							<text class="txt3">（天）</text>
						</view>
					</view>
					<view class="item-btn" @click="projectContractPage(project.buyInRecordId)">查看合同</view>
				</view>
				<view class="item-time">购买时间：{{ project.buyInTime }}</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			projects: [],
			selectedProject: '',
			refreshKey:0
		}
	},
	onLoad() {
		this.findHoldingProject();
	},
	onShow(){
		this.refreshKey += 1;
	},
	methods: {

		showAmountModal(record) {
			this.selectedProject = record;
			this.$refs.amountModal.open();
		},

		showRateModal(record) {
			this.selectedProject = record;
			this.$refs.rateModal.open();
		},

		projectContractPage(id) {
			uni.navigateTo({
				url: '../projectContract/projectContract?id=' + id
			});
		},

		findHoldingProject() {
			var that = this;
			uni.$uv.http.get('/buyInRecord/findHoldingProject').then(res => {
				that.projects = res.data;
			});
		},

	}
}
</script>

<style>
page {
	height: auto !important;
	background: url('/static/img/my_bg.png') no-repeat;
	background-size: 100% 100%;
	background-color: #FFFFFF;
}
.main{
	width: 100vw;
	height: 100vh;
	padding-top: 32rpx;
	box-sizing: border-box;
	overflow-y: scroll;
}

.check-btn {
	font-size: 25rpx;
	color: #E4D494;
	width: 120rpx;
	line-height: 36rpx;
	background: rgba(228, 212, 148, 0.1);
	border-radius: 24rpx 24rpx 24rpx 24rpx;
	text-align: center;
}

.item {
	width: 686rpx;
	margin: 0 32rpx 32rpx 32rpx;
	background: #FFF;
	border-radius: 28rpx 28rpx 28rpx 28rpx;
	padding: 32rpx 28rpx 20rpx;
	box-sizing: border-box;
}

.item-title {
	font-weight: bold;
	font-size: 32rpx;
	color: #000;
	line-height: 28rpx;
	display: flex;
	justify-content: space-between;
}

.item-content {
	padding: 28rpx;
	box-sizing: border-box;
	width: 630rpx;
	height: 240rpx;
	background: #F5F7FB;
	border-radius: 28rpx 28rpx 28rpx 28rpx;
}

.item-content-w {
	display: flex;
}

.item-content-box {
	flex: 1;
	align-items: center;
	justify-content: center;
}

.txt1 {
	display: block;
	text-align: center;
	font-weight: bold;
	font-size: 28rpx;
	color: #C9AC31;
	line-height: 28rpx;
}

.txt2,
.txt3 {
	margin-top: 12rpx;
	display: block;
	font-size: 24rpx;
	text-align: center;
	color: #8C949D;
	line-height: 24rpx;
}

.txt3 {
	margin-top: 4rpx;
}

.item-btn {
	width: 574rpx;
	height: 68rpx;
	margin-top: 28rpx;
	background: #FEE19E;
	border-radius: 38rpx 38rpx 38rpx 38rpx;
	font-weight: bold;
	font-size: 28rpx;
	color: #192131;
	line-height: 68rpx;
	text-align: center;
}

.item-time {
	margin-top: 20rpx;
	font-size: 24rpx;
	color: rgba(255, 255, 255, 0.4);
	line-height: 24rpx;
}

.holding-project-item {
	display: flex;
	align-items: center;
}

.invest-info {
	display: flex;
	padding-top: 16rpx;
	padding-bottom: 16rpx;
}

.invest-info-item {
	flex: 1;
	text-align: center;
}

.invest-info-item-label {
	font-size: smaller;
	color: #888;
	display: flex;
	align-items: center;
	justify-content: center;
}

.invest-info-item-label2 {
	font-size: smaller;
	color: #888;
	display: flex;
	align-items: center;
	justify-content: center;
}

.invest-info-item-value {
	font-size: smaller;
	padding-top: 24rpx;
	color: royalblue;
	font-weight: bold;
	display: flex;
	align-items: center;
	justify-content: center;
}

.last-buy-in {
	display: flex;
	justify-content: end;
}

.project-name {
	color: #333;
	font-size: 28rpx;
	font-weight: bold;
	padding-top: 12rpx;
}

.view-contract {
	size: 20rpx;
}

.project-pic-r-block {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	height: 200rpx;
	width: 200rpx;
	text-align: center;
	background: linear-gradient(45deg, #0068b7, #b9d4e9);
	border-radius: 16rpx;
	color: white;
}

.project-pic-r {
	padding-left: 8px;
}

.project-pic-l {
	flex: 1;
}

.project-pic {
	display: flex;
	align-items: center;
}

.project {
	padding-left: 32rpx;
	padding-right: 32rpx;
	padding-bottom: 32rpx;
}
</style>